<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="6">
            <a-form-model-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNumber">
              <a-input readOnly v-model="model.serialNumber" placeholder="请输入序号"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="零件名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partName">
              <a-input readOnly  v-model="model.partName" placeholder="请输入零件名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="中文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chineseName">
              <a-input readOnly v-model="model.chineseName" placeholder="请输入中文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="英文名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="englishName">
              <a-input readOnly v-model="model.englishName" placeholder="请输入英文名"  ></a-input>
            </a-form-model-item>
          </a-col>
          </a-row>

          <a-row>
            <a-col :span="6">
            <a-form-model-item label="零件规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partSpecification">
              <a-input readOnly v-model="model.partSpecification" placeholder="请输入零件规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="材料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="material">
              <a-input readOnly v-model="model.material" placeholder="请输入材料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="number">
              <a-input readOnly v-model="model.number" placeholder="请输入数量"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input readOnly v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          </a-row>
         
          <!-- <a-col :span="24">
            <a-form-model-item label="bom状态（1.新增2.变更3.取消）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bomStatus">
              <a-input-number v-model="model.bomStatus" placeholder="请输入bom状态（1.新增2.变更3.取消）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转益模的状态（1.未转2.已转）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transferBenefitModelStatus">
              <a-input-number v-model="model.transferBenefitModelStatus" placeholder="请输入转益模的状态（1.未转2.已转）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customFields1String">
              <a-input v-model="model.customFields1String" placeholder="请输入自定义字段1" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customFields2">
              <a-input v-model="model.customFields2" placeholder="请输入自定义字段2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customFields3">
              <a-input v-model="model.customFields3" placeholder="请输入自定义字段3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customFields4">
              <a-input v-model="model.customFields4" placeholder="请输入自定义字段4"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自定义字段5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customFields5">
              <a-input v-model="model.customFields5" placeholder="请输入自定义字段5"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模具设计BOM主表id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chDesignBomMasterId">
              <a-input v-model="model.chDesignBomMasterId" placeholder="请输入模具设计BOM主表id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否删除（0.正常1.删除）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDelete">
              <a-input-number v-model="model.isDelete" placeholder="请输入是否删除（0.正常1.删除）" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <a-divider style="margin-bottom: 40px" />
          <a-row>
            <a-col :span="8">
            <a-form-model-item label="设计BOM序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designSerialNo">
              <a-input v-model="model.designSerialNo" placeholder="请输入设计BOM序号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCode">
              <a-input v-model="model.materialCode" placeholder="请输入物料编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialName">
              <a-input v-model="model.materialName" placeholder="请输入物料名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          </a-row>

          <a-row>
            <a-col :span="8">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specifications">
              <a-input v-model="model.specifications" placeholder="请输入规格"  ></a-input>
            </a-form-model-item>
          </a-col>
            <a-col :span="8">
            <a-form-model-item label="规格说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specificationsDescription">
              <a-input v-model="model.specificationsDescription" placeholder="请输入规格说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="重量(KG)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weight">
              <a-input v-model="model.weight" placeholder="请输入规格说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="designNum">
              <a-input v-model="model.designNum" placeholder="请输入数量"  ></a-input>
            </a-form-model-item>
          </a-col>
         
          </a-row>
          
          <a-row>
            <a-col :span="8">
            <a-form-model-item label="请购备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseRequisitionRemarks">
              <a-input v-model="model.purchaseRequisitionRemarks" placeholder="请输入请购备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="T100需求日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="t100DemandDate">
              <a-input v-model="model.t100DemandDate" placeholder="请输入T100需求日期"  ></a-input>
            </a-form-model-item>
          </a-col>
            <a-col :span="8">
            <a-form-model-item label="ERP代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="erpCode">
              <a-input v-model="model.erpCode" placeholder="请输入ERP代码"  ></a-input>
            </a-form-model-item>
          </a-col>
         
          </a-row>

          <a-row>
            <a-col :span="8">
            <a-form-model-item label="部件编号/零件名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partsType">
              <a-input v-model="model.partsType" placeholder="请输入部件编号/零件名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="未加余量的尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withoutAllowanceDimension">
              <a-input v-model="model.withoutAllowanceDimension" placeholder="请输入未加余量的尺寸"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="拼料和不订料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mixMaterialsAndNotOrder">
              <a-input v-model="model.mixMaterialsAndNotOrder" placeholder="请输入拼料和不订料"  ></a-input>
            </a-form-model-item>
          </a-col>
            
          </a-row>

          <a-row>
            <a-col :span="8">
            <a-form-model-item label="原材料/配件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rawMaterialsAndAccessories">
              <a-input v-model="model.rawMaterialsAndAccessories" placeholder="请输入原材料/配件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="T100单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="t100Units">
              <a-input v-model="model.t100Units" placeholder="请输入T100单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="T100模具编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="t100MoldNo">
              <a-input v-model="model.t100MoldNo" placeholder="请输入T100模具编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          </a-row>
          
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChOrderBomForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chOrderBom/add",
          edit: "/ch/chOrderBom/edit",
          queryById: "/ch/chOrderBom/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>